package com.starry.home.viewmodel.hospital

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.switchMap
import com.starry.home.logic.network.Repository
import com.starry.core.viewmodel.BaseViewModel

/**
 * Package:com.starry.dotpen_patients.viewmodel.hospital
 * Author:starr
 * Time:2024/1/4 20:47
 * Description:
 */
class HospitalViewModel : BaseViewModel() {

    private val _hospitalSection: MutableLiveData<ArrayList<Array<String>>> = MutableLiveData(
        arrayListOf(
            arrayOf("某医生1", "某医生2", "某医生3", "某医生4"),
            arrayOf("某医生3", "某医生4", "某医生5", "某医生6")
        )
    )

    val hospitalSection: LiveData<ArrayList<Array<String>>> = _hospitalSection

    fun onHospitalSectionChanged(sections: ArrayList<Array<String>>) {
        _hospitalSection.value = sections
    }

    private val _sectionListLiveData = MutableLiveData<Int>()

    val sectionList = _sectionListLiveData.switchMap { params: Int -> Repository.getSectionList(params) }

    fun getSectionList(params: Int) {
        _sectionListLiveData.value = params
    }

    private val _doctorListLiveData = MutableLiveData<String>()
    val doctorList = _doctorListLiveData.switchMap { ysSection: String -> Repository.getDoctorList(ysSection) }
    fun getDoctorList(ysSection: String) {
        _doctorListLiveData.value = ysSection
    }

    private val _ysInfoLiveData = MutableLiveData<String>()
    val ysInfo = _ysInfoLiveData.switchMap { ysName: String -> Repository.queryYsByName(ysName) }
    fun queryYsByName(ysName: String) {
        Log.i("lixu", "viewmodel: ")
        _ysInfoLiveData.value = ysName
    }
}